//
//  ZFRegisterViewController.m
//  HappilyLoan
//
//  Created by zainishenbian on 2017/3/22.
//  Copyright © 2017年 zongqingxiangqian. All rights reserved.
//

#import "ZFRegisterViewController.h"
#import "ZFSetPswViewController.h"//设置密码
#import "ZFHeader.h"
#import "ZLCLinkUrlViewController.h"

@interface ZFRegisterViewController ()<UITextFieldDelegate>
@property(nonatomic,strong)AlertBoxView *alertBox;
@end

@implementation ZFRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"注册";
    _protocolButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _protocolButton.titleLabel.numberOfLines = 2;
    _protocolButton.titleLabel.textAlignment = NSTextAlignmentCenter;
      [_nextStepbutton setShadowWidth:2 shadowHeight:2 shadowColor:Main_Color1 radius:10];
    [_nextStepbutton setShadowWidth:2 shadowHeight:2 shadowColor:Main_Color1 radius:10];
    [self.view addSubview:self.alertBox];
}
#pragma mark ———— textfield delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // Check for total length
    NSUInteger proposedNewLength = textField.text.length - range.length + string.length;
    
    if (proposedNewLength > 11) {
        
        return NO;
    }
    
    return YES;
}
#pragma mark ———— button的点击事件
//注册设置密码
- (IBAction)nextStep:(id)sender {
    
    if ([ZFLoginConfig isValidatePhone:[ZFPulicAPI replaceBlank:_phoneTF.text]]){
    if ([ZFPulicAPI replaceBlank:_phoneTF.text].length >= 11) {
        
        if ([ZFLoginConfig isValidatePhone:[ZFPulicAPI replaceBlank:_phoneTF.text]]) {
            
            ZFSetPswViewController *setPswVC = [ZFSetPswViewController new];
            setPswVC.phone = [ZFPulicAPI replaceBlank:_phoneTF.text];
            [self.navigationController pushViewController:setPswVC animated:YES];
         }
    }
    }else{
       [_alertBox appearAndDisappearAlertWithString:@"请输入正确的手机号"];
    }
}
- (IBAction)ProtocolButton:(UIButton *)sender {
    ZLCLinkUrlViewController *URLVC = [[ZLCLinkUrlViewController alloc]init];
    URLVC.titleStr = @"注册协议";
    URLVC.url = @"http://106.15.102.162/protocol/agreementHYJR/regester-agreement.html";
    [self.navigationController pushViewController:URLVC animated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"register"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"register"];
}
- (AlertBoxView *)alertBox
{
    if (!_alertBox) {
        _alertBox = [[AlertBoxView alloc] init];
    }
    return _alertBox;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
